package com.py.wemedia.controller.v1;

import com.py.model.admin.dtos.ChannelDto;
import com.py.model.common.dtos.ResponseResult;
import com.py.model.wemedia.pojos.WmChannel;
import com.py.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2022/11/10 10:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService channelService;

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult list(){
        return ResponseResult.okResult(channelService.list());
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){

        return channelService.saveChannel(wmChannel);
    }


    /**
     * 删除频道
     * /api/v1/channel/del/{id}
     * @param id
     */

    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){

        channelService.delete(id);
        return ResponseResult.okResult(null);

    }


    /**
     * 修改数据  /api/v1/channel/update
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){

        return channelService.update(wmChannel);
    }


    //查询
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody ChannelDto dto){

        ResponseResult result = channelService.findAll(dto);
        return result;
    }
}